package com.gthncz;

import java.util.Scanner;

public class Duoduo22 {


    private static int dfs(int[][] matrix, boolean[][] visited, int i, int j, int n, int m, int length) {
        if (i == n || j == m || i < 0 || j < 0 || matrix[i][j] == 0) {
            return length;
        }

        ++length;
        visited[i][j] = true;
        if (i-1 >=0 && !visited[i-1][j]) length = dfs(matrix, visited, i-1, j, n, m, length);
        if (j-1 >=0 && !visited[i][j-1]) length = dfs(matrix, visited , i, j-1, n, m, length);
        if (i+1 < n && !visited[i+1][j]) length = dfs(matrix, visited , i+1, j, n, m, length);
        if (j+1 < m && !visited[i][j+1]) length = dfs(matrix, visited , i, j+1, n, m, length);

        return length;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] matrix = new int[n][m];

        for (int i=0; i<n ; ++i) {
            for (int j=0; j<m; ++j) {
                matrix[i][j] = sc.nextInt();
            }
        }

        int ans = 0;

        for (int i=0; i<n ; ++i) {
            for (int j=0; j<m; ++j) {
                if (matrix[i][j] == 0) {
                    boolean[][] visited = new boolean[n][m];
                    matrix[i][j] = 1;
                    ans = Math.max(ans, dfs(matrix, visited, i, j, n, m, 0));
                    matrix[i][j] = 0;
                }
            }
        }

        System.out.printf("%d", ans);
    }

}
